package xyz.labmem.lipx.core.context

import cn.hutool.core.thread.ExecutorBuilder
import cn.hutool.core.util.RandomUtil
import xyz.labmem.lipx.core.client.core.LabSSHPenetrationClient
import xyz.labmem.lipx.core.entity.ClientConfig
import xyz.labmem.lipx.core.entity.ServerConfig
import xyz.labmem.lipx.core.server.core.LabNettyPenetrationServer
import java.util.*
import java.util.concurrent.*

/**
 * @description: do something
 * @author: ltty
 * @date: 2022/8/9 17:33
 */
object AppContext {

    object Client {

        var allList = HashMap<String, ClientConfig>()

        var groupRList = LinkedList<String>()
        var groupFList = LinkedList<String>()

        val connectList = ConcurrentHashMap<String, LabSSHPenetrationClient>()
        val connectingList = ConcurrentHashMap<String, LabSSHPenetrationClient>()

        fun makeId(): String {
            val id = RandomUtil.randomString(6)
            return if (allList.containsKey(id)) makeId() else id
        }

        val parallelPool: ThreadPoolExecutor = ExecutorBuilder.create()
            .setCorePoolSize(10)
            .setMaxPoolSize(10)
            .setWorkQueue(LinkedBlockingQueue(Integer.MAX_VALUE))
            .build()

        val rowPool: ExecutorService = Executors.newSingleThreadExecutor()
    }

    object Server {

        val server = LabNettyPenetrationServer()

        var cacheData: ServerConfig? = null

        var startDate: String = "-"

    }

}